package btb.net;

import btb.net.CNetwork.NClientList;
import btb.util.CLogger;

public class CChannel extends ANetDossier
{
	public class NChannelProfile extends NANetProfile
	{		
		public NChannelProfile()
		{
			super();
		}
		
		public NChannelProfile(CChannel _channel, String _channelName)
		{
			super(_channel, _channelName);
		}
		
		public int getNumUsers()
		{
			CChannel channel = (CChannel) owner;
			return channel.subscribers.getCount();
		}
		
		public String snapShot()
		{
			CChannel channel = (CChannel) owner;
			String returnStr = "";
			
			returnStr += "Channel: " + heading + "\n\n";;
			returnStr += "Players joined: " + channel.subscribers.getCount() + "\n\n";
			
			return returnStr;
		}
	}
	
	protected NClientList subscribers;
	private NChannelProfile profile;
	
	public CChannel(String _channelName)
	{
		subscribers = new NClientList();
		profile = new NChannelProfile(this, _channelName);
	}

	public void addSubscriber(CUser _user)
	{
		subscribers.add(_user);
	}
	
	public void removeSubscriberByName(String _username)
	{
		subscribers.removeByIndex(subscribers.findClientByName(_username));
	}
	
	public NClientList getSubscribers(){return subscribers;}
	
	@Override
	public void setProfile(NANetProfile _profile)
	{
		try
		{
			profile = (NChannelProfile) _profile;
			profile.setOwner(this);
		} 
		catch(Exception e)
		{
			CLogger.cond_error("engine/net", "Attempted to set profile object for CChannel object; general Exception thrown.");
		}
	}

	@Override
	public NANetProfile getProfile(){return profile;}
}
